package controller;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/3/21 11:39
 * @description：我的第一个servlet类
 * @modified By：
 * @version: 1.0
 */
public class MyServlet extends HttpServlet {
    public MyServlet() {
        System.out.println("构造器调用了");
    }

    @Override
    public void destroy() {
        System.out.println("MyServlet销毁了");
    }

    @Override
    public void init() throws ServletException {
        System.out.println("MyServlet初始化了");
    }

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        //获取上下文
        ServletContext servletContext = getServletContext();
        //获取全局配置
        String encode = servletContext.getInitParameter("encode");
        System.out.println("MyServlet中获取全局配置encode"+encode);
        String userKey = getInitParameter("userKey");
        System.out.println("MyServlet中获取局部参数："+userKey);
        String name = req.getParameter("name");
        System.out.println(name+"的请求到达"+new Date());
    }

   /* @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("处理业务");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }*/
}
